/*
 * CircuitDialog.cpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   CircuitDialog.cpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   29 jan 2013
 */


#include <wx/wx.h>
#include <boost/shared_ptr.hpp>

#include "CircuitPanel.hpp"

#include "CircuitDialog.hpp"

using boost::shared_ptr;

namespace tltgen {

  BEGIN_EVENT_TABLE(CircuitDialog, wxDialog)
  EVT_BUTTON(wxID_OK, CircuitDialog::onOkButtonClicked)
  EVT_BUTTON(wxID_CANCEL, CircuitDialog::onCancelButtonClicked)
  END_EVENT_TABLE()

  CircuitDialog::CircuitDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
    : wxDialog(parent, id, title, pos, size, style, name)
  {
    initializeComponents();
  }

  CircuitDialog::~CircuitDialog()
  { }

  void CircuitDialog::initializeComponents()
  {
    wxSizer* vbox = new wxBoxSizer(wxVERTICAL);

    this->circuitPanel = new CircuitPanel(this, wxID_ANY);
    vbox->Add(circuitPanel, 0, wxALL, 10);

    wxSizer *buttonSizer = CreateButtonSizer(wxOK | wxCANCEL);
    vbox->Add(buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10);

    SetSizer(vbox);
    vbox->SetSizeHints(this);
  }

  void CircuitDialog::onOkButtonClicked(wxCommandEvent& event)
  {
    //TODO: validate values
    EndModal(wxID_OK);
  }

  void CircuitDialog::onCancelButtonClicked(wxCommandEvent& event)
  {
    EndModal(wxID_CANCEL);
  }


  void CircuitDialog::setAdcValues(const shared_ptr<AnalogToDigitalConverter const>& adc)
  {
    this->circuitPanel->setAdcValues(adc);
  }
  void CircuitDialog::setCircuitValues(const shared_ptr<Circuit const>& circuit)
  {
    this->circuitPanel->setCircuitValues(circuit);
  }
  
  shared_ptr<AnalogToDigitalConverter> CircuitDialog::createAnalogToDigitalConverter() const
  {
    return this->circuitPanel->createAnalogToDigitalConverter();
  }
  shared_ptr<Circuit> CircuitDialog::createCircuit() const
  {
    return this->circuitPanel->createCircuit();
  }

}

